﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwObracunVirmaniProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwObracunVirmaniProviderBaseCore : EntityViewProviderBase<VwObracunVirmani>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwObracunVirmani&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwObracunVirmani&gt;"/></returns>
		protected static VList&lt;VwObracunVirmani&gt; Fill(DataSet dataSet, VList<VwObracunVirmani> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwObracunVirmani>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwObracunVirmani&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwObracunVirmani>"/></returns>
		protected static VList&lt;VwObracunVirmani&gt; Fill(DataTable dataTable, VList<VwObracunVirmani> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwObracunVirmani c = new VwObracunVirmani();
					c.NalogodavateljNaziv = (Convert.IsDBNull(row["NalogodavateljNaziv"]))?string.Empty:(System.String)row["NalogodavateljNaziv"];
					c.NalogodavateljSjediste = (Convert.IsDBNull(row["NalogodavateljSjediste"]))?string.Empty:(System.String)row["NalogodavateljSjediste"];
					c.NalogodavateljRacun = (Convert.IsDBNull(row["NalogodavateljRacun"]))?string.Empty:(System.String)row["NalogodavateljRacun"];
					c.NalogodavateljModel = (Convert.IsDBNull(row["NalogodavateljModel"]))?string.Empty:(System.String)row["NalogodavateljModel"];
					c.NalogodavateljPoziv = (Convert.IsDBNull(row["NalogodavateljPoziv"]))?string.Empty:(System.String)row["NalogodavateljPoziv"];
					c.PrimateljNaziv = (Convert.IsDBNull(row["PrimateljNaziv"]))?string.Empty:(System.String)row["PrimateljNaziv"];
					c.PrimateljSjediste = (Convert.IsDBNull(row["PrimateljSjediste"]))?string.Empty:(System.String)row["PrimateljSjediste"];
					c.OpisPlacanja = (Convert.IsDBNull(row["OpisPlacanja"]))?string.Empty:(System.String)row["OpisPlacanja"];
					c.ZiroRacunZaPorezPrirez = (Convert.IsDBNull(row["ZiroRacunZaPorezPrirez"]))?string.Empty:(System.String)row["ZiroRacunZaPorezPrirez"];
					c.Iznos = (Convert.IsDBNull(row["Iznos"]))?0:(System.Decimal?)row["Iznos"];
					c.Model = (Convert.IsDBNull(row["Model"]))?string.Empty:(System.String)row["Model"];
					c.PozivNaBroj = (Convert.IsDBNull(row["PozivNaBroj"]))?string.Empty:(System.String)row["PozivNaBroj"];
					c.IDObracun = (Convert.IsDBNull(row["IDObracun"]))?(int)0:(System.Int32)row["IDObracun"];
					c.DatumIsplate = (Convert.IsDBNull(row["DatumIsplate"]))?DateTime.MinValue:(System.DateTime)row["DatumIsplate"];
					c.ZadModel = (Convert.IsDBNull(row["ZadModel"]))?string.Empty:(System.String)row["ZadModel"];
					c.ZadPoziv = (Convert.IsDBNull(row["ZadPoziv"]))?string.Empty:(System.String)row["ZadPoziv"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwObracunVirmani&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwObracunVirmani&gt;"/></returns>
		protected VList<VwObracunVirmani> Fill(IDataReader reader, VList<VwObracunVirmani> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwObracunVirmani entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwObracunVirmani>("VwObracunVirmani",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwObracunVirmani();
					}
					entity.NalogodavateljNaziv = reader.IsDBNull(reader.GetOrdinal("NalogodavateljNaziv")) ? null : (System.String)reader["NalogodavateljNaziv"];
					//entity.NalogodavateljNaziv = (Convert.IsDBNull(reader["NalogodavateljNaziv"]))?string.Empty:(System.String)reader["NalogodavateljNaziv"];
					entity.NalogodavateljSjediste = reader.IsDBNull(reader.GetOrdinal("NalogodavateljSjediste")) ? null : (System.String)reader["NalogodavateljSjediste"];
					//entity.NalogodavateljSjediste = (Convert.IsDBNull(reader["NalogodavateljSjediste"]))?string.Empty:(System.String)reader["NalogodavateljSjediste"];
					entity.NalogodavateljRacun = reader.IsDBNull(reader.GetOrdinal("NalogodavateljRacun")) ? null : (System.String)reader["NalogodavateljRacun"];
					//entity.NalogodavateljRacun = (Convert.IsDBNull(reader["NalogodavateljRacun"]))?string.Empty:(System.String)reader["NalogodavateljRacun"];
					entity.NalogodavateljModel = reader.IsDBNull(reader.GetOrdinal("NalogodavateljModel")) ? null : (System.String)reader["NalogodavateljModel"];
					//entity.NalogodavateljModel = (Convert.IsDBNull(reader["NalogodavateljModel"]))?string.Empty:(System.String)reader["NalogodavateljModel"];
					entity.NalogodavateljPoziv = reader.IsDBNull(reader.GetOrdinal("NalogodavateljPoziv")) ? null : (System.String)reader["NalogodavateljPoziv"];
					//entity.NalogodavateljPoziv = (Convert.IsDBNull(reader["NalogodavateljPoziv"]))?string.Empty:(System.String)reader["NalogodavateljPoziv"];
					entity.PrimateljNaziv = reader.IsDBNull(reader.GetOrdinal("PrimateljNaziv")) ? null : (System.String)reader["PrimateljNaziv"];
					//entity.PrimateljNaziv = (Convert.IsDBNull(reader["PrimateljNaziv"]))?string.Empty:(System.String)reader["PrimateljNaziv"];
					entity.PrimateljSjediste = reader.IsDBNull(reader.GetOrdinal("PrimateljSjediste")) ? null : (System.String)reader["PrimateljSjediste"];
					//entity.PrimateljSjediste = (Convert.IsDBNull(reader["PrimateljSjediste"]))?string.Empty:(System.String)reader["PrimateljSjediste"];
					entity.OpisPlacanja = reader.IsDBNull(reader.GetOrdinal("OpisPlacanja")) ? null : (System.String)reader["OpisPlacanja"];
					//entity.OpisPlacanja = (Convert.IsDBNull(reader["OpisPlacanja"]))?string.Empty:(System.String)reader["OpisPlacanja"];
					entity.ZiroRacunZaPorezPrirez = reader.IsDBNull(reader.GetOrdinal("ZiroRacunZaPorezPrirez")) ? null : (System.String)reader["ZiroRacunZaPorezPrirez"];
					//entity.ZiroRacunZaPorezPrirez = (Convert.IsDBNull(reader["ZiroRacunZaPorezPrirez"]))?string.Empty:(System.String)reader["ZiroRacunZaPorezPrirez"];
					entity.Iznos = reader.IsDBNull(reader.GetOrdinal("Iznos")) ? null : (System.Decimal?)reader["Iznos"];
					//entity.Iznos = (Convert.IsDBNull(reader["Iznos"]))?0:(System.Decimal?)reader["Iznos"];
					entity.Model = reader.IsDBNull(reader.GetOrdinal("Model")) ? null : (System.String)reader["Model"];
					//entity.Model = (Convert.IsDBNull(reader["Model"]))?string.Empty:(System.String)reader["Model"];
					entity.PozivNaBroj = reader.IsDBNull(reader.GetOrdinal("PozivNaBroj")) ? null : (System.String)reader["PozivNaBroj"];
					//entity.PozivNaBroj = (Convert.IsDBNull(reader["PozivNaBroj"]))?string.Empty:(System.String)reader["PozivNaBroj"];
					entity.IDObracun = (System.Int32)reader["IDObracun"];
					//entity.IDObracun = (Convert.IsDBNull(reader["IDObracun"]))?(int)0:(System.Int32)reader["IDObracun"];
					entity.DatumIsplate = (System.DateTime)reader["DatumIsplate"];
					//entity.DatumIsplate = (Convert.IsDBNull(reader["DatumIsplate"]))?DateTime.MinValue:(System.DateTime)reader["DatumIsplate"];
					entity.ZadModel = reader.IsDBNull(reader.GetOrdinal("ZadModel")) ? null : (System.String)reader["ZadModel"];
					//entity.ZadModel = (Convert.IsDBNull(reader["ZadModel"]))?string.Empty:(System.String)reader["ZadModel"];
					entity.ZadPoziv = reader.IsDBNull(reader.GetOrdinal("ZadPoziv")) ? null : (System.String)reader["ZadPoziv"];
					//entity.ZadPoziv = (Convert.IsDBNull(reader["ZadPoziv"]))?string.Empty:(System.String)reader["ZadPoziv"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwObracunVirmani"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunVirmani"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwObracunVirmani entity)
		{
			reader.Read();
			entity.NalogodavateljNaziv = reader.IsDBNull(reader.GetOrdinal("NalogodavateljNaziv")) ? null : (System.String)reader["NalogodavateljNaziv"];
			//entity.NalogodavateljNaziv = (Convert.IsDBNull(reader["NalogodavateljNaziv"]))?string.Empty:(System.String)reader["NalogodavateljNaziv"];
			entity.NalogodavateljSjediste = reader.IsDBNull(reader.GetOrdinal("NalogodavateljSjediste")) ? null : (System.String)reader["NalogodavateljSjediste"];
			//entity.NalogodavateljSjediste = (Convert.IsDBNull(reader["NalogodavateljSjediste"]))?string.Empty:(System.String)reader["NalogodavateljSjediste"];
			entity.NalogodavateljRacun = reader.IsDBNull(reader.GetOrdinal("NalogodavateljRacun")) ? null : (System.String)reader["NalogodavateljRacun"];
			//entity.NalogodavateljRacun = (Convert.IsDBNull(reader["NalogodavateljRacun"]))?string.Empty:(System.String)reader["NalogodavateljRacun"];
			entity.NalogodavateljModel = reader.IsDBNull(reader.GetOrdinal("NalogodavateljModel")) ? null : (System.String)reader["NalogodavateljModel"];
			//entity.NalogodavateljModel = (Convert.IsDBNull(reader["NalogodavateljModel"]))?string.Empty:(System.String)reader["NalogodavateljModel"];
			entity.NalogodavateljPoziv = reader.IsDBNull(reader.GetOrdinal("NalogodavateljPoziv")) ? null : (System.String)reader["NalogodavateljPoziv"];
			//entity.NalogodavateljPoziv = (Convert.IsDBNull(reader["NalogodavateljPoziv"]))?string.Empty:(System.String)reader["NalogodavateljPoziv"];
			entity.PrimateljNaziv = reader.IsDBNull(reader.GetOrdinal("PrimateljNaziv")) ? null : (System.String)reader["PrimateljNaziv"];
			//entity.PrimateljNaziv = (Convert.IsDBNull(reader["PrimateljNaziv"]))?string.Empty:(System.String)reader["PrimateljNaziv"];
			entity.PrimateljSjediste = reader.IsDBNull(reader.GetOrdinal("PrimateljSjediste")) ? null : (System.String)reader["PrimateljSjediste"];
			//entity.PrimateljSjediste = (Convert.IsDBNull(reader["PrimateljSjediste"]))?string.Empty:(System.String)reader["PrimateljSjediste"];
			entity.OpisPlacanja = reader.IsDBNull(reader.GetOrdinal("OpisPlacanja")) ? null : (System.String)reader["OpisPlacanja"];
			//entity.OpisPlacanja = (Convert.IsDBNull(reader["OpisPlacanja"]))?string.Empty:(System.String)reader["OpisPlacanja"];
			entity.ZiroRacunZaPorezPrirez = reader.IsDBNull(reader.GetOrdinal("ZiroRacunZaPorezPrirez")) ? null : (System.String)reader["ZiroRacunZaPorezPrirez"];
			//entity.ZiroRacunZaPorezPrirez = (Convert.IsDBNull(reader["ZiroRacunZaPorezPrirez"]))?string.Empty:(System.String)reader["ZiroRacunZaPorezPrirez"];
			entity.Iznos = reader.IsDBNull(reader.GetOrdinal("Iznos")) ? null : (System.Decimal?)reader["Iznos"];
			//entity.Iznos = (Convert.IsDBNull(reader["Iznos"]))?0:(System.Decimal?)reader["Iznos"];
			entity.Model = reader.IsDBNull(reader.GetOrdinal("Model")) ? null : (System.String)reader["Model"];
			//entity.Model = (Convert.IsDBNull(reader["Model"]))?string.Empty:(System.String)reader["Model"];
			entity.PozivNaBroj = reader.IsDBNull(reader.GetOrdinal("PozivNaBroj")) ? null : (System.String)reader["PozivNaBroj"];
			//entity.PozivNaBroj = (Convert.IsDBNull(reader["PozivNaBroj"]))?string.Empty:(System.String)reader["PozivNaBroj"];
			entity.IDObracun = (System.Int32)reader["IDObracun"];
			//entity.IDObracun = (Convert.IsDBNull(reader["IDObracun"]))?(int)0:(System.Int32)reader["IDObracun"];
			entity.DatumIsplate = (System.DateTime)reader["DatumIsplate"];
			//entity.DatumIsplate = (Convert.IsDBNull(reader["DatumIsplate"]))?DateTime.MinValue:(System.DateTime)reader["DatumIsplate"];
			entity.ZadModel = reader.IsDBNull(reader.GetOrdinal("ZadModel")) ? null : (System.String)reader["ZadModel"];
			//entity.ZadModel = (Convert.IsDBNull(reader["ZadModel"]))?string.Empty:(System.String)reader["ZadModel"];
			entity.ZadPoziv = reader.IsDBNull(reader.GetOrdinal("ZadPoziv")) ? null : (System.String)reader["ZadPoziv"];
			//entity.ZadPoziv = (Convert.IsDBNull(reader["ZadPoziv"]))?string.Empty:(System.String)reader["ZadPoziv"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwObracunVirmani"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunVirmani"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwObracunVirmani entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.NalogodavateljNaziv = (Convert.IsDBNull(dataRow["NalogodavateljNaziv"]))?string.Empty:(System.String)dataRow["NalogodavateljNaziv"];
			entity.NalogodavateljSjediste = (Convert.IsDBNull(dataRow["NalogodavateljSjediste"]))?string.Empty:(System.String)dataRow["NalogodavateljSjediste"];
			entity.NalogodavateljRacun = (Convert.IsDBNull(dataRow["NalogodavateljRacun"]))?string.Empty:(System.String)dataRow["NalogodavateljRacun"];
			entity.NalogodavateljModel = (Convert.IsDBNull(dataRow["NalogodavateljModel"]))?string.Empty:(System.String)dataRow["NalogodavateljModel"];
			entity.NalogodavateljPoziv = (Convert.IsDBNull(dataRow["NalogodavateljPoziv"]))?string.Empty:(System.String)dataRow["NalogodavateljPoziv"];
			entity.PrimateljNaziv = (Convert.IsDBNull(dataRow["PrimateljNaziv"]))?string.Empty:(System.String)dataRow["PrimateljNaziv"];
			entity.PrimateljSjediste = (Convert.IsDBNull(dataRow["PrimateljSjediste"]))?string.Empty:(System.String)dataRow["PrimateljSjediste"];
			entity.OpisPlacanja = (Convert.IsDBNull(dataRow["OpisPlacanja"]))?string.Empty:(System.String)dataRow["OpisPlacanja"];
			entity.ZiroRacunZaPorezPrirez = (Convert.IsDBNull(dataRow["ZiroRacunZaPorezPrirez"]))?string.Empty:(System.String)dataRow["ZiroRacunZaPorezPrirez"];
			entity.Iznos = (Convert.IsDBNull(dataRow["Iznos"]))?0:(System.Decimal?)dataRow["Iznos"];
			entity.Model = (Convert.IsDBNull(dataRow["Model"]))?string.Empty:(System.String)dataRow["Model"];
			entity.PozivNaBroj = (Convert.IsDBNull(dataRow["PozivNaBroj"]))?string.Empty:(System.String)dataRow["PozivNaBroj"];
			entity.IDObracun = (Convert.IsDBNull(dataRow["IDObracun"]))?(int)0:(System.Int32)dataRow["IDObracun"];
			entity.DatumIsplate = (Convert.IsDBNull(dataRow["DatumIsplate"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumIsplate"];
			entity.ZadModel = (Convert.IsDBNull(dataRow["ZadModel"]))?string.Empty:(System.String)dataRow["ZadModel"];
			entity.ZadPoziv = (Convert.IsDBNull(dataRow["ZadPoziv"]))?string.Empty:(System.String)dataRow["ZadPoziv"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwObracunVirmaniFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunVirmani"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunVirmaniFilterBuilder : SqlFilterBuilder<VwObracunVirmaniColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunVirmaniFilterBuilder class.
		/// </summary>
		public VwObracunVirmaniFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunVirmaniFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunVirmaniFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunVirmaniFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunVirmaniFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunVirmaniFilterBuilder

	#region VwObracunVirmaniParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunVirmani"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunVirmaniParameterBuilder : ParameterizedSqlFilterBuilder<VwObracunVirmaniColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunVirmaniParameterBuilder class.
		/// </summary>
		public VwObracunVirmaniParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunVirmaniParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunVirmaniParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunVirmaniParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunVirmaniParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunVirmaniParameterBuilder
} // end namespace
